<template>
  <view>
    <view class="goods-list">
      <!-- block不支持点击事件 -->
      <view v-for="(goods,i) in goodsList" :key="i" @click="gotoDetail(goods)">
        <my-goods :goods="goods"></my-goods>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        //请求桉树对象
        queryObj: {
          query: '',
          cid:'',
          pagenum: 1,
          pagesize: 10
        },
        goodsList:[],
        total: 0,
        isLoading: false,
      };
    },
    methods: {
      gotoDetail(item){
        console.log("--------------------")
        uni.navigateTo({
          url:'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id
        })
      },
      async getGoodsList(cb){
        this.isLoading = true;
        const {data: res} = await uni.$http.get('/api/public/v1/goods/search',this.queryObj);
        //关闭节流阀
        this.isLoading = false;
        cb && cb();
        if(res.meta.status !== 200) return uni.$showMsg();
        // this.goodsList = res.message.goods;
        this.goodsList = [...this.goodsList,...res.message.goods]
         console.log(this.goodsList)
        this.total = res.message.total;
      }
    },
    onReachBottom() {
      if(this.queryObj.pagenum * this.queryObj.pagesize >= this.total) return uni.$showMsg('数据加载完毕！');
      if(this.isLoading) return;
      this.queryObj.pagenum++;
      this.getGoodsList()
    },
    onPullDownRefresh(){
      this.queryObj.pagenum = 0;
      this.total = 0;
      this.isLoading = 0;
      this.goodsList = [];
      this.getGoodsList(()=>uni.stopPullDownRefresh())
    },
    onLoad(options) {
      this.queryObj.query = options.query || '';
      this.queryObj.cid = options.cid || '';
      console.log(this.queryObj);
      this.getGoodsList();
     
    }
  }
</script>

